home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / icon / packages.lha / packages / atari / ats.arc / TESTS.ARC / MEANDER.ICN < prev    next >
Text File  |  1990-03-28  |  786b  |  34 lines

  1. #
  2. #          M E A N D E R I N G   S T R I N G S
  3. #
  4.  
  5. #  This main procedure accepts specifications for meandering strings
  6. #  from standard input with the alphabet separated from the length by
  7. #  a colon.
  8.  
  9. procedure main()
  10.    local line, alpha, n
  11.    while line := read() do {
  12.       line ? if {
  13.          alpha := tab(upto(':')) &
  14.          move(1) &
  15.          n := integer(tab(0))
  16.          }
  17.          then write(meander(alpha,n)) 
  18.          else stop("*** erroneous input ***")
  19.       }
  20. end
  21.  
  22. procedure meander(alpha,n)
  23.    local result, t, i, c, k
  24.    i := k := *alpha
  25.    t := n-1
  26.    result := repl(alpha[1],t)
  27.    while c := alpha[i] do {
  28.       if find(result[-t:0] || c,result)
  29.       then i -:= 1
  30.       else {result ||:= c; i := k}
  31.       }
  32.    return result
  33. end
  34.